From 036d6f6d1679df205dcfaf07b7b148bf8cb0bea8 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Tue, 2 Jun 2015 09:56:44 -0400 Subject: [PATCH] tests: add a test for submodule packaging --- tests/test_cargo_package.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/test_cargo_package.rs b/tests/test_cargo_package.rs index 1fb2bc77a..dd47a3cb9 100644 --- a/tests/test_cargo_package.rs +++ b/tests/test_cargo_package.rs @@ -1,13 +1,14 @@ use std::fs::File; use std::io::Cursor; use std::io::prelude::*; +use std::path::Path; use cargo::util::process; use flate2::read::GzDecoder; use git2; use tar::Archive; -use support::{project, execs, cargo_dir, paths, git}; +use support::{project, execs, cargo_dir, paths, git, path2url}; use support::{PACKAGING, VERIFYING, COMPILING, ARCHIVING}; use hamcrest::{assert_that, existing_file}; @@ -282,3 +283,36 @@ test!(package_new_git_repo { {archiving} [..] ", packaging = PACKAGING, archiving = ARCHIVING))); }); + +test!(package_git_submodule { + use std::str::from_utf8; + + let project = git::new("foo", |project| { + project.file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = ["foo@example.com"] + license = "MIT" + description = "foo" + repository = "foo" + "#) + .file("src/lib.rs", "pub fn foo() {}") + }).unwrap(); + let library = git::new("bar", |library| { + library.file("Makefile", "all:") + }).unwrap(); + + let repository = git2::Repository::open(&project.root()).unwrap(); + let url = path2url(library.root()).to_string(); + git::add_submodule(&repository, &url, Path::new("bar")); + git::commit(&repository); + + let repository = git2::Repository::open(&project.root().join("bar")).unwrap(); + repository.reset(&repository.revparse_single("HEAD").unwrap(), + git2::ResetType::Hard, None).unwrap(); + + let result = project.cargo("package").arg("--no-verify").arg("-v").exec_with_output().unwrap(); + assert!(result.status.success()); + assert!(from_utf8(&result.stdout).unwrap().contains(&format!("{} bar/Makefile", ARCHIVING))); +}); -- 2.30.2